"""
#!/usr/bin/env python
# -*- coding:utf-8 -*-
@Project : All_Designer
@File : Device_Find.py
@Author : RuanYaoHuang
@Time : 2023/3/7 21:17

"""
import time
from arena_api.system import system

class Device_Find():
    def __init__(self):
        self.devices = None

    def findDivice(self):
        tries = 0
        tries_max = 6
        sleep_time_secs = 10
        while tries < tries_max:  # Wait for device for 60 seconds
            self.devices = system.create_device()
            if not self.devices:
                print(
                    f'Try {tries + 1} of {tries_max}: waiting for {sleep_time_secs} '
                    f'secs for a device to be connected!')
                for sec_count in range(sleep_time_secs):
                    time.sleep(1)
                    print(f'{sec_count + 1} seconds passed ',
                          '.' * sec_count, end='\r')
                    tries += 1
            else:
                print(f'Created {len(self.devices)} device(s)')
                self.device = self.devices[0]
                break
        else:
            return
        return self.devices

if __name__ == '__main__':
    device_find = Device_Find()
    device = device_find.findDivice()
    print(device)